package com.hellobike.haxing.modules.shop.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import com.hellobike.haxing.modules.shop.entity.ShopWithdrewMonthCount;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.util.List;
import java.math.BigDecimal;

/**
 * <p>
 * 每月提现成功总金额，次年清空 Mapper 接口
 * </p>
 *
 * @author clz
 * @since 2020-02-15
 */
public interface ShopWithdrewMonthCountMapper extends BaseMapper<ShopWithdrewMonthCount> {
    /**
     * 门店月提现金额
     * @param shopId
     * @return
     */
    @Select("select withdrew_amount from t_shop_withdrew_month_count where deleted=0 and shop_id=#{shopId}")
    BigDecimal getMonthAmount(Long shopId);

    /**
     * 审核通过修改月统计金额
     * @return
     */
    int saveMonthAmount(@Param("withdrewAmount") BigDecimal withdrewAmount,@Param("shopId") Long shopId,@Param("withdrewMonth") String withdrewMonth);

    /**
     * 查询小于当前月记录
     * @param withMonth
     */
    @Update("select * from  t_shop_withdrew_month_count where #{withMonth}>withdrew_month and deleted=0")
    List<ShopWithdrewMonthCount> queryMonthLtList(String withMonth);

    @Update("update t_shop_withdrew_month_count set deleted=1,update_time=now() where id=#{id} and deleted=0")
    void deleteMonthCountId(Long id);
}
